package hbase.HbaseStudy;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;

import java.io.IOException;

public class Hb07_deleteTable {
    private static String tableName = "person";
    private static Configuration conf;
    private static Connection HConn;
    private static Admin admin;

    private static void dropTable(String tableName) throws IOException {
        admin.deleteTable(TableName.valueOf(tableName));
    }

    public static void main(String[] args) throws IOException {
        conf = HBaseConfiguration.create();
        HConn = ConnectionFactory.createConnection(conf);
        admin = HConn.getAdmin();

        try {
            // 坚=检查表是否禁用
            if (admin.isTableDisabled(TableName.valueOf(tableName))) {
                // 表已经禁用
                dropTable(tableName);
                System.out.println("delete ok");
            } else {
                // 先设置表禁用
                admin.disableTable(TableName.valueOf(tableName));
                dropTable(tableName);
                System.out.println("delete ok");
            }
        } finally {
            admin.close();
            HConn.close();
        }
    }
}
